//
//  CAServiceFeedbackVC.m
//  CleanerAir_Project
//
//  Created by 付亚杰 on 16/6/27.
//  Copyright © 2016年 Beijing Colin El Internet. All rights reserved.
//

#import "CAServiceFeedbackVC.h"

@interface CAServiceFeedbackVC ()<UITextViewDelegate>{
    
    NSInteger _questionType;//2为产品反馈、4为对商品、商家有意见
}

//体验问题
@property (weak, nonatomic) IBOutlet UIImageView *experienceImageView;
//商家商品问题
@property (weak, nonatomic) IBOutlet UIImageView *merchantsOrGoodsImageView;

@property (weak, nonatomic) IBOutlet UITextView *questionTextView;

@property (weak, nonatomic) IBOutlet UILabel *telLabel;

@end

@implementation CAServiceFeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"服务反馈";
    
    _questionType = 4;
    self.questionTextView.delegate = self;
    
    
    [self.experienceImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(experienceImageViewClick)]];
    
    [self.merchantsOrGoodsImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(merchantsOrGoodsImageViewClick)]];
    
    self.questionTextView.layer.borderWidth = 1.5f;
    [self.questionTextView.layer setBorderColor:CGColorCreate(CGColorSpaceCreateDeviceRGB(),(CGFloat[]){ 220/255, 220/255, 220/255, 0.2 })];
    
    [self.telLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(telLabelClick)]];
    
//    self.view.backgroundColor=[UIColor yellowColor];
    
    // Do any additional setup after loading the view from its nib.
}

#pragma mark -- 拨打电话
- (void)telLabelClick{
    
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",self.telLabel.text];
    //            NSLog(@"str======%@",str);
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
}

#pragma mark -- textViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    self.questionTextView.text = @"";
    return YES;
}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    if ([self.questionTextView.text isEqualToString:@""]) {
        self.questionTextView.text = @"请在此描述您的问题和意见，我们将及时处理，您的意见对我们至关重要......";
    }
    return YES;
}

- (void)merchantsOrGoodsImageViewClick{
    
    _questionType = 4;
    self.experienceImageView.image = [UIImage imageNamed:@"选择圆圈.png"];
    self.merchantsOrGoodsImageView.image = [UIImage imageNamed:@"选择.png"];
    
}

- (void)experienceImageViewClick{
    
    _questionType = 2;
    self.experienceImageView.image = [UIImage imageNamed:@"选择.png"];
    self.merchantsOrGoodsImageView.image = [UIImage imageNamed:@"选择圆圈.png"];
    
}


#pragma mark -- 提交问题
- (IBAction)commitQuestion:(id)sender {
    
    if ([self.questionTextView.text isEqualToString:@""] || [self.questionTextView.text isEqualToString:@"请在此描述您的问题和意见，我们将及时处理，您的意见对我们至关重要......"]) {
        [ShowMessage showCenterViewMessage:@"请填写问题或意见"];
        [self.questionTextView becomeFirstResponder];
        return;
    }
    
    [self commitQuestionToService];
    
}

- (void)commitQuestionToService{
    
    [self showIndicator:@"正在提交，请稍后..."];
    
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:[LoginSingleton sharedLoginSingleton].token,@"token",[LoginSingleton sharedLoginSingleton].loginModel.ids,@"id",[NSString stringWithFormat:@"%ld",_questionType],@"type",self.questionTextView.text,@"content", nil];
    
    
    __weak __typeof(self) weakSelf = self;
    
    [HTTPManager post:GET_URLString(@"/Api/Msgs/send") parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [self hideIndicator];
        if ([responseObject[@"msg"] isEqualToString:@"成功"]) {
            
            [ShowMessage showCenterViewMessage:@"提交成功，感谢您的支持"];
            
            [weakSelf.navigationController popViewControllerAnimated:YES];
            
        }else{
            
            [ShowMessage showCenterViewMessage:responseObject[@"msg"]];
        }
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hideIndicator];
        
    }];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
